package com.six.controller;

import com.six.pojo.BillDetail;
import com.six.pojo.dto.BillDetailDto;
import com.six.result.Result;
import com.six.result.ResultUtils;
import com.six.service.BillDetailService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "发票详细信息接口文档")
@RestController
@RequestMapping("/billDetail")
@Slf4j
@CrossOrigin
public class BillDetailController {

    @Autowired
    private BillDetailService detailService;

    @GetMapping("/listById/{billId}")
    public Result findList(@PathVariable Long billId){
        List<BillDetailDto> detailDtoList = detailService.findByBillId(billId);
        return ResultUtils.buildSuccess((long) detailDtoList.size(),detailDtoList);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result delete(@PathVariable Long id){
        detailService.removeById(id);
        return ResultUtils.buildSuccess();
    }

    @PostMapping("/add")
    public Result add(@RequestBody BillDetail billDetail){
        billDetail.setId(null);
        detailService.save(billDetail);
        return ResultUtils.buildSuccess();
    }

    @PutMapping("/update")
    public Result update(@RequestBody BillDetail billDetail){
        detailService.updateById(billDetail);
        return ResultUtils.buildSuccess();
    }

}
